//切换审核状态
	$(".control-mode").click(function() {
		if (!$(this).hasClass("active")) {
			$(".control-mode").removeClass("active");
			$(this).addClass("active");
			if($(this).attr("data-value")=="bound")
				{
				$("#MyTable2_wrapper").css("display","none");
				$("#MyTable1_wrapper").css("display","block");
				}
			else if($(this).attr("data-value")=="unbound")
			{
				$("#MyTable2_wrapper").css("display","block");
				$("#MyTable1_wrapper").css("display","none");
				}
		}
	});


	
	//加载列表信息
	loadTableData();
	function loadTableData(){
		zxTips_loading({
			loadicon:true,//是否添加加载图标（默认添加）
			loadtxt:"加载中"//加载说明
		});
		var formObject={}
		$.ajax({
			type:"POST",
			url:DataURL+"bank/user/card?status=bind",
			dataType:'json', 
			async : false,
			contentType :"application/json;charset=UTF-8",
			data: JSON.stringify(formObject),//传递给服务器的参数
			success:function(data){
				if(checkTokenError(data)){
				console.log(data.content);
				$(".control-mode .bound").text(data.content.length);
				EntryTable(data.content,1);
				}
			},
	        error:function(data){
	            console.log(data)
	            zxTips_short({
	    			txt : "系统错误"
	    			});
	        }
		});
		$.ajax({
			type:"POST",
			url:DataURL+"bank/user/card?status=notBind",
			dataType:'json', 
			async : false,
			contentType :"application/json;charset=UTF-8",
			data: JSON.stringify(formObject),//传递给服务器的参数
			success:function(data){
				if(checkTokenError(data)){
				console.log(data.content);
				$(".control-mode .unbound").text(data.content.length);
				EntryTable(data.content,2);
				}
			},
	        error:function(data){
	            console.log(data)
	            zxTips_short({
	    			txt : "系统错误"
	    			});
	        }
		});
		zxTips_loadingend();
	}
	
	
//输入数据
	function EntryTable(TableData,type) {
		TableData.sort(DataSortByDate);
		var TableList = "";
		if(type=="1"){
		for (var i = 0; i < TableData.length; i++) {
			TableList += '<tr>';
			TableList += '<td>'+'<img src="'+TableData[i].avatar+'"/><div>'+TableData[i].name+'</div></td>';
			TableList += '<td><span>'+ CheckSex(TableData[i].sex)+'</span></td>';

			TableList += '<td>'+jsGetAge(TableData[i].birthday)+'</td>';
			TableList += '<td>'+CheckLevel(TableData[i].custFlag)+'</td>';
			TableList += '<td class="item-id">'+TableData[i].phone+'</td>';
			TableList += '<td>'+TableData[i].openBranName+'</td>';
			TableList += '<td>'+TableData[i].createDate+'</td>';
			TableList += '</tr>';
		}
		$('#MyTable1').find('tbody').html(TableList);
		}
		else if(type=="2"){
			for (var i = 0; i < TableData.length; i++) {
				TableList += '<tr>';
				TableList += '<td>'+'<img src="'+TableData[i].avatar+'"/><div>'+TableData[i].name+'</div></td>';
				TableList += '<td>'+CheckSex(TableData[i].sex)+'</td>';
				TableList += '<td>-</td>';
				TableList += '<td>-</td>';
				TableList += '<td>-</td>';
				TableList += '<td>-</td>';
				TableList += '<td>-</td>';
				TableList += '</tr>';
			}
			$('#MyTable2').find('tbody').html(TableList);
		}
		
	}
	
	//根据时间排序
	function DataSortByDate(x, y) {
        return (x.createDate < y.createDate) ? 1 : -1
    }
	//转化性别
	function CheckSex(sex){
		if(sex==1){return "男";}
		else if(sex==2){return "女";}
		else {return "未知";}
	}
	//转化等级
	function CheckLevel(level){
		var flag=level/10;
		switch(flag)
		{
		case 0:
			return "普通客户";
		  break;
		case 1:
			return "黄金客户";
		  break;
		case 2:
			return "白金客户";
		  break;
		case 3:
			return "钻石客户";
		  break;
		case 4:
			return "本行员工";
		  break;
		default:
			return "未知";
		}
	}
	//转化岁数
	function jsGetAge(strBirthday){
		var strBir=timetrans(strBirthday);
	    var returnAge;  
	    var strBirthdayArr=strBir.split("-");  
	    var birthYear = strBirthdayArr[0];  
	    var birthMonth = strBirthdayArr[1];  
	    var birthDay = strBirthdayArr[2];  
	      
	    d = new Date();  
	    var nowYear = d.getFullYear();  
	    var nowMonth = d.getMonth() + 1;  
	    var nowDay = d.getDate();  
	      
	    if(nowYear == birthYear){  
	        returnAge = 0;//同年 则为0岁  
	    }  
	    else{  
	        var ageDiff = nowYear - birthYear ; //年之差  
	        if(ageDiff > 0){  
	            if(nowMonth == birthMonth) {  
	                var dayDiff = nowDay - birthDay;//日之差  
	                if(dayDiff < 0)  
	                {  
	                    returnAge = ageDiff - 1;  
	                }  
	                else  
	                {  
	                    returnAge = ageDiff ;  
	                }  
	            }  
	            else  
	            {  
	                var monthDiff = nowMonth - birthMonth;//月之差  
	                if(monthDiff < 0)  
	                {  
	                    returnAge = ageDiff - 1;  
	                }  
	                else  
	                {  
	                    returnAge = ageDiff ;  
	                }  
	            }  
	        }  
	        else  
	        {  
	            returnAge = -1;//返回-1 表示出生日期输入错误 晚于今天  
	        }  
	    }  
	      
	    return returnAge;//返回周岁年龄  
	      
	}
	//时间戳转日期
	function timetrans(date){
	    var date = new Date(date*1000);//如果date为10位不需要乘1000
	    var Y = date.getFullYear() + '-';
	    var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
	    var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
	    var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
	    var m = (date.getMinutes() <10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
	    var s = (date.getSeconds() <10 ? '0' + date.getSeconds() : date.getSeconds());
	    return Y+M+D+h+m+s;
	}
	//调用列表插件
	var tableData1 = $('#MyTable1').DataTable({
		
		"info" : false,
		"lengthChange" : false,
		"pageLength" : 8,
		"ordering" : false,
		language : {
			"sEmptyTable" : "没有数据！",
			"zeroRecords" : "没有搜索到结果！",
			"oPaginate" : {
				"sPrevious" : '<',
				"sNext" : '>',
			},
		}
	});
	var tableData2 = $('#MyTable2').DataTable({
		
		"info" : false,
		"lengthChange" : false,
		"pageLength" : 8,
		"ordering" : false,
		language : {
			"sEmptyTable" : "没有数据！",
			"zeroRecords" : "没有搜索到结果！",
			"oPaginate" : {
				"sPrevious" : '<',
				"sNext" : '>',
			},
		}
	});
